package com.aliware.tianchi.test.random;

/**
 * @author lorne
 * @date 2019/6/30
 * @description
 */
public class UniformDistributionHelper {

    private UniformDistributionTool uniformDistributionHelper;

    private int maxSize;
    private double[] chances;

    private UniformDistributionHelper(int maxSize, double[] chances){
        this.maxSize = maxSize;
        this.chances = chances;
        uniformDistributionHelper = new UniformDistributionTool(maxSize, chances);
    }


    public int nextInt(){
        if(uniformDistributionHelper.finish()){
            uniformDistributionHelper = new UniformDistributionTool(maxSize, chances);
        }
        return uniformDistributionHelper.nextInt();
    }

    public static void main(String[] args) {
        double chances [] = {0.1,0.3,0.3,0.3};
        int count = 100000000;
        UniformDistributionHelper uniformDistributionHelper =  new UniformDistributionHelper(100,chances);

        int index = 0;
        for(int i=0;i<count;i++){
            int val = uniformDistributionHelper.nextInt();
            if(val<=10.0){
                index++;
            }
        }
        System.out.println("<=40:"+index);
    }

}
